package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;

public class EVEN extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    Object localObject = null;
    for (int i = 0; i < paramArrayOfObject.length; ++i)
    {
      localObject = paramArrayOfObject[i];
      if (localObject instanceof Number)
      {
        if ((localObject instanceof Long) && (((Number)localObject).longValue() % 2L == 0L))
          return new Long(((Number)localObject).longValue());
        double d = ((Number)localObject).doubleValue();
        long l = ()d % 2L;
        if (d > 0.0D)
        {
          if (l == 0L)
            return new Long(()d + 2L);
          return new Long(()d + 1L);
        }
        if (l == 0L)
          return new Long(()d - 2L);
        return new Long(()d - 1L);
      }
    }
    return new Integer(0);
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "EVEN(number):返回沿绝对值增大方向取整后最接近的偶数。使用该函数可以处理那些成对出现的对象。\nnumber:所要取整的数值。\n不论正负号如何，数值都朝着远离 0 的方向舍入。如果 number 恰好是偶数，则不须进行任何舍入处理。\n示例:\nEVEN(1.5) 等于 2\nEVEN(3) 等于 4\nEVEN(2) 等于 2\nEVEN(-1) 等于 -2";
  }

  public String getEN()
  {
    return "EVEN(number): Returns number rounded up to the nearest even integer. You can use this function for processing items that come in twos.\nNumber is the value to round.\nRegardless of the sign of number, a value is rounded up when adjusted away from zero. If number is an even integer, no rounding occurs. \n\nExample:\n   EVEN(1.5) = 2\n   EVEN(3) = 4\n   EVEN(2) = 2\n   EVEN(-1) = -2";
  }
}